//
//  BGContactViewController.m
//  bigMall
//
//  Created by 大魔王 on 2016/12/29.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGContactViewController.h"

@interface BGContactViewController () <UIGestureRecognizerDelegate>

@end

@implementation BGContactViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self cteateUi];
    
}

- (void)cteateUi {
    
    //小简介
    UILabel *summary = [[UILabel alloc] initWithFrame:CGRectMake(21, 74, BGWidth - 42, MAXFLOAT)];
    summary.textAlignment = NSTextAlignmentLeft;
    summary.numberOfLines = 0;
    summary.text = [NSString stringWithFormat:@"简介：%@",@"aaaaa"];
    [summary sizeToFit];
    summary.y = 74;
    [self.view addSubview:summary];
    
    //修饰线
    UIView *a = [[UIView alloc] initWithFrame:CGRectMake(0, summary.bottom + 10, BGWidth, 1)];
    a.backgroundColor = dockwhite_;
    [self.view addSubview:a];
    
    //联系人
    UILabel *conatctUs = [[UILabel alloc] initWithFrame:CGRectMake(21, a.bottom + 10, BGWidth - 42, 21)];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"联系方式：%@",@"10086"]];
    [attrStr addAttribute:NSForegroundColorAttributeName value:blue_ range:NSMakeRange(5, [attrStr length] - 5)];
    conatctUs.attributedText = attrStr;
    conatctUs.userInteractionEnabled = YES;
    [self.view addSubview:conatctUs];
    
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(callPhone)];
    tap.delegate = self;
    [conatctUs addGestureRecognizer:tap];
    
}

- (void)callPhone {
    
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"10086"]]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"10086"]]];
    }else {
        [self showMessage:@"暂时无法拨打的"];
    }

}
- (void)showMessage:(NSString *)message {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    
    [alertController addAction:okAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
}

#pragma mark gestureDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
